from extensions import db
from datetime import datetime

class QualityTrace(db.Model):
    __tablename__ = 'quality_traces'
    
    id = db.Column(db.Integer, primary_key=True)
    batch_number = db.Column(db.String(50), nullable=False, index=True)
    product_name = db.Column(db.String(100), nullable=False)
    production_date = db.Column(db.DateTime, nullable=False)
    expiration_date = db.Column(db.DateTime, nullable=False)
    manufacturer = db.Column(db.String(100), nullable=False)
    storage_condition = db.Column(db.String(200))
    quality_standard = db.Column(db.String(200))
    inspector = db.Column(db.String(50))
    inspection_date = db.Column(db.DateTime)
    inspection_result = db.Column(db.String(20))  # passed, failed, pending
    temperature_records = db.Column(db.Text)  # JSON string of temperature history
    humidity_records = db.Column(db.Text)  # JSON string of humidity history
    notes = db.Column(db.Text)
    created_at = db.Column(db.DateTime, default=datetime.now)
    updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
    created_by = db.Column(db.Integer, db.ForeignKey('users.id')) 